<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- created by lishaoxiong on 2017年9月8日 下午1:51:20--%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>js/jquery专项</title>
		<link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.min.css" />
		
	</head>
	<body>
		<div class="am-container dataDiv">
			<section class="am-panel am-panel-primary">
			  <header class="am-panel-hd">
			    <h3 class="am-panel-title">考试功能演示</h3>
			  </header>
			  <div class="am-panel-bd">
			
					<table class="am-table am-table-bordered am-text-center">
						<thead>
							<tr>
								<th colspan="3">
									<button title="点击此按钮刷新下方表格数据，ajax处理" class="am-btn am-btn-primary">刷新数据</button>
								</th>
							</tr>
							
						</thead>
						<tbody>
						<c:forEach items="${T }" var="t">
							<tr>
								<td><input type="checkbox" id="c" name="checkid" value="${t.name }-${t.age}" onclick="countCheck()"></td>
								<td>${t.name }</td>
								<td>${t.age }岁</td>
							</tr>
							</c:forEach>
							<tr>
								
								<td colspan="3">
									<a class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为选中状态" onclick="checkAll()" name="chkall">全选</a>
									<a class="am-btn am-btn-primary" title="点击后将所有数据的checkbox修改为未选中状态" onclick="ncheckAll()" name="nchkall">全不选</a>
									<a class="am-btn am-btn-primary" title="点击后，已选择的checkbox改为未选择，未选择的checkbox改为已选择" onclick="CheckOthers()" name="ochkall">反选</a>
						
								<button class="am-btn am-btn-warning" title="点击后提交已选择数据的value值" onclick="formSubmit()">提交已选择数据</button>
								</td>
							</tr>
						</tbody>
					</table>
			
					<div id="z">
						
					</div>
			  </div>
			</section>
		</div>
		<script src="static/js/jquery-1.12.4.min.js"></script>
		<script src="static/js/jquery-confirm.min.js"></script>
		<script type="text/javascript">
			function checkAll(){
				var checkboxes = document.getElementsByName('checkid');
				for(var i = 0; i< checkboxes.length; i++){
					var c = checkboxes[i];
					if(c.name != 'chkall'){
						c.checked = true;
					}		
				}
			}
			function ncheckAll(){
				var checkboxes = document.getElementsByName('checkid');
				for(var i = 0; i< checkboxes.length; i++){
					var c = checkboxes[i];
					if(c.name != 'nchkall'){
						c.checked = false;
					}		
				}
			}
			function CheckOthers(){
				var checkboxes = document.getElementsByName('checkid');
			    for (var i=0;i<checkboxes.length;i++)
			    {
			        var e = checkboxes[i];
			        if (e.name != 'ochkall')
			            if (e.checked==false)
			            {
			                e.checked = true;
			            }
			            else
			            {
			                e.checked = false;
			            }
			    }
			}
			function countCheck(){
				var count = 0;
				var checkboxes = document.getElementsByName('checkid');
				for(var i = 0; i<checkboxes.length; i++){
					var c = checkboxes[i];
					if(c.checked){
						count++;
					}
				}
			}
			function formSubmit(){
				var count = 0;
				var checkboxes = document.getElementsByName('checkid');	
				for(var i = 0; i<checkboxes.length; i++){
					var c = checkboxes[i];
					if(c.checked){
						count++;
					}				
						console.log('====')
					if(c.checked){
						$.post('sex.do',{cc:$('#c').val()},function(result){
							$('#z').text(result.ss)
						});		
					}	
						
				}
			}
			</script>
	</body>
</html>